package com.example.jdbc_demo.util;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBC_Demo {
    static {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
    }
    public static java.sql.Connection getConnection(){
        try{
            return DriverManager.getConnection("jdbc:mysql://172.18.92.57:3306/javaweb","rjgc21","rjgc21");
        }catch(SQLException e){
            e.printStackTrace();
        }
        return null;
    }
    public static java.sql.Statement getStatment(){
        try{
            return getConnection().createStatement();
        }catch(SQLException e){
            e.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args){
        try{
            java.sql.Statement statement = getStatment();
            java.sql.ResultSet resultSet = statement.executeQuery("select * from user");
            while (resultSet.next()){
                System.out.println(resultSet.getString("username"));
                System.out.println(resultSet.getString("password"));
            }
            resultSet.close();
        }
        catch (SQLException e){
            e.printStackTrace();
        }
    }
}
